//index.js
//获取应用实例
const app = getApp()
var server = require('../../utils/server');
import {
  init
} from "../../utils/init";
import {
  formatDateCN,
  formatDateNow,
  formatDate_, formatDateTime, formatDate
} from "../../utils/util"

Page({
  data: {
    list: [],
    current: 1,
    pageSize: 10,
    allPage: 0,
    loading: false,
    scrollTop: 0,
    userInfo: {},
    tableData: [],
    columns: [],
    tableYHeight: 1000,
    token: null,
    isShow: true,
    showName: new Date().toLocaleDateString(),
    keyword: "",
    // 时段选择插件-开始
    isPickerRender: false,
    isPickerShow: false,
    startTime: "开始时间",
    endTime: "结束时间",
    pickerConfig: {
      endDate: true,                          // 是否需要结束时间，为true时显示开始时间和结束时间两个picker
      column: "day",                       //可选的最小时间范围hour、minute、secend
      dateLimit: true,                        //是否现在时间可选范围，false时可选任意时间；未数字n时，范围是当前时间的最近n天
      initStartTime:'2023-01-01',    //picker初始时间，默认当前时间
      initEndTime: "2023-12-01",     //picker初始结束时间，默认当前时间
      limitStartTime: "2000-01-01",  //最小可选时间
      limitEndTime: "2099-12-31"     //最大可选时间
    },
    // 时段选择插件-结束
    keyword: "",
    showMoreSearchStatus: false,
    areaSearchList: [],
    cateUsernameSearchList: [],
    bussinessSearchList: [],
    bussinessSearchAllList: [],
    permissionUsernameSearchList: [],
    showArea: false,//控制下拉列表的显示隐藏，false隐藏、true显示
    indexArea: null,//选择的下拉列表下标
    showCateUsername: false,//控制下拉列表的显示隐藏，false隐藏、true显示
    indexCateUsername: null,//选择的下拉列表下标
    showPermissionUsername: false,//控制下拉列表的显示隐藏，false隐藏、true显示
    indexPermissionUsername: null,//选择的下拉列表下标
    showBussiness: false,//控制下拉列表的显示隐藏，false隐藏、true显示
    indexBussiness: null,//选择的下拉列表下标
    searchStartDate: "",
    searchEndDate: "",
    statusSearchList: [
      {
        id: 1,
        sysValueName: "待推送",
      },
      {
        id: 2,
        sysValueName: "核价中",
      },
      {
        id: 3,
        sysValueName: "等待中",
      },
      {
        id: 4,
        sysValueName: "一次竞价",
      },
      {
        id: 5,
        sysValueName: "二次竞价",
      },
      {
        id: 7,
        sysValueName: "已完成",
      }
    ],
    showStatus: false,
    indexStatus: null,
    statusMap: null,
    timeArray: [ '全部', '近7日', '近30日', '自定义区间' ],
    selectIndex: 0,
    showTime: '',
    navactive: 0,
    statusValueMap: {},
    statusValueList: [],
    navChangeIndex: 0,
    firstJoinNum: 1,
    status1Num: 0,
    status2Num: 0,
    statusNumMap: {},
    orderStatusName: []
  },

  // 新增项目
  addProject(){
    wx.navigateTo({
      url: '/pages/addProject/addProject',
    })
  },
  changeStatusChoose(e){
    let item = e.currentTarget.dataset.item
    let list = this.data.statusValueList
    list.forEach((item,index) => {
      if(index == e.currentTarget.dataset.index){
       item.isChoose = !item.isChoose
       
      }
    })
    this.setData({
      statusValueList: list,
      current: 1,
      tableData: [],
    })
    setTimeout(()=>{
      this.getList()
    }, 500)
  },

  navchange(e){
    let index = e.detail.index
    let list = this.data.statusValueMap[index+1]
    list.forEach(item => {
      item.isChoose = false
      if(item.value == 99){
        item.isChoose = true
      }
      if(item.value == 93){
        item.isChoose = true
      }

    })
    this.setData({
      statusValueList: list,
      current: 1,
      tableData: [],
      navChangeIndex: index,
    })
    setTimeout(()=>{
      this.getList()
    }, 500)
  },

  bindTimePickerChange: function(e) {
    if(e.detail.value == 3){
      let pickerConfig = this.data.pickerConfig
      pickerConfig.initStartTime = formatDate_(new Date())
      pickerConfig.initEndTime = formatDate_(new Date())
      this.setData({
        pickerConfig: pickerConfig,
        isPickerShow: true,
        isPickerRender: true,
        chartHide: true
      });
    }else{
      this.setData({
        selectIndex: e.detail.value
      })
      if(e.detail.value && e.detail.value == 1){
        // 近7天
        this.setData({
          startTime: new Date().getTime() - 7 * 24 * 60 * 60 * 1000,
          endTime: new Date().getTime(),
          current: 1,
        })
        setTimeout(()=>{
          this.getList()
        },200)
      }else if(e.detail.value && e.detail.value == 2){
        // 近30天
        this.setData({
          startTime: new Date().getTime() - 30 * 24 * 60 * 60 * 1000,
          endTime: new Date().getTime(),
          current: 1,
        })
        setTimeout(()=>{
          this.getList()
        },200)
      }
    }
  },
  // 选择日期
  bindStartDateChange(e){
    let that = this
    this.setData({
      searchStartDate: e.detail.value
    })
    setTimeout(()=>{
      that.getList()
    }, 500)
  },
  bindEndDateChange(e){
    let that = this
    this.setData({
      searchEndDate: e.detail.value
    })
    setTimeout(()=>{
      that.getList()
    }, 500)
  },

  // 清空筛选条件
  clearSearch(){
    let that = this
    this.setData({
      indexArea: null,
      indexCateUsername: null,
      indexPermissionUsername: null,
      indexBussiness: null,
      keyword: "",
      searchStartDate: "",
      searchEndDate: "",
      indexStatus: null,
      selectIndex: 0,
      current: 1,
    })
    wx.showLoading({
      title: '加载中',
      mask: true,
    })
    setTimeout(() => {
      that.getList()
    }, 1000)
  },
  goSearch(){
    let that = this
    that.setData({
      current: 1,
      tableData: [],
    })
    wx.showLoading({
      title: '加载中',
      mask: true,
    })
    setTimeout(() => {
      that.getList()
    }, 1000)
  },
  showMoreSearch(){
    if(!this.data.userInfo || !this.data.userInfo.userType){
      return
    }
    this.getSysList()
    this.setData({
      showMoreSearchStatus: !this.data.showMoreSearchStatus
    })
  },
  bindblurKeyword(e){
    let that = this
    let keyword = e.detail.value
    that.setData({
      keyword: keyword
    })
  },
  bindblurKeywordGetList(e){
    let that = this
    let keyword = e.detail.value
    that.setData({
      keyword: keyword,
      current: 1,
      tableData: [],
    })
    wx.showLoading({
      title: '加载中',
      mask: true,
    })
    setTimeout(()=>{
      that.getList()
    }, 1000)
  },

  pickerShow: function() {
    this.setData({
      isPickerShow: true,
      isPickerRender: true,
      chartHide: true
    });
  },
  pickerHide: function() {
    this.setData({
      isPickerShow: false,
      chartHide: false
    });
  },

  bindPickerChange: function(e) {
    this.getData(this.data.sensorList[e.detail.value].id);
    this.setData({
      index: e.detail.value,
      sensorId: this.data.sensorList[e.detail.value].id
    });
  },
  setPickerTime: function(val) {
    let data = val.detail;
    let showTime = formatDateNow(new Date(data.startTime), new Date()) + '-' + formatDateNow(new Date(data.endTime), new Date())
    this.setData({
      startTime: data.startTime,
      endTime: data.endTime,
      showTime: showTime,
      selectIndex: 3,
      current: 1,
    });
    setTimeout(()=>{
      this.getList()
    },200)
  },
  
  // 授权
  getSubMsg(){
    let that = this
    // 授权订阅消息
    console.log("订阅授权")
    wx.requestSubscribeMessage({
      tmplIds: ['gM28ZeiMzmJkEhB2mXnCSS0eKtmsPKuKPXFeE4Pv1aE','CdyMJ4XLi-8_Ls3FswgKfYZmbThOoFook0vW99Rgbt0'], // 最多支持3条
      success(res) {
        console.log("订阅===》",res)
        // 'accept'表示用户同意订阅该条id对应的模板消息
        if (res['gM28ZeiMzmJkEhB2mXnCSS0eKtmsPKuKPXFeE4Pv1aE'] === 'accept' || res['CdyMJ4XLi-8_Ls3FswgKfYZmbThOoFook0vW99Rgbt0'] === 'accept') {
          // 用户同意订阅，调用云函数或服务器接口发送订阅消息
          console.log("订阅成功")
          that.doSubscribe()
        }
      }
    })
  },
  doSubscribe() {
    let params = {}
    server.post("/app/user/subscribeUserMsg", params).then(res => {
      if (res.key === 1000) {
        let userInfo = this.data.userInfo
        userInfo.isSubscribeMessage = 2
        wx.setStorageSync('userInfo', userInfo)
        this.setData({
          userInfo: userInfo
        })
      }
    });
  },
  goLogin(){
    let that = this
    wx.login({
      success: (res1) => {
        setTimeout(function () {
          wx.hideLoading()
        }, 2000)
        wx.navigateTo({
          url: '/pages/login/login?code=' + res1.code,
        })
      }
    });
  },
  getWXUserInfo(){
    wx.getUserProfile({
      desc: '用于完善用户资料', // 声明获取用户个人信息后的用途，后续会展示在弹窗中，请谨慎填写
      success: (res) => {
        wx.showLoading({
          title: '加载中',
          mask: true,
        })
        wx.login({
          success: (res1) => {
            setTimeout(function () {
              wx.hideLoading()
            }, 2000)
            wx.navigateTo({
              url: '/pages/login/login?code=' + res1.code,
            })
          }
        });
      },
      fail: (res) => {
        console.log("res返回错误===>",res)
      },
      complete: (res) => {
        console.log("res返回===>",res)
      }
    })
  },

  getSearchStatusList(){
    let that = this
    let params = {}
    let userInfo = that.data.userInfo
    if(userInfo.userType == 2){
      // 开拓者
      params.sysLabelIds = 17
    }else if(userInfo.userType == 1){
      params.sysLabelIds = 16
    }
    server.post("/app/user/getSysLabelValueManageList", params).then(res => {
      if (res.key === 1000) {
        // orderStatusName
        let orderStatusName = []
        let statusList = []
        let list = res.result.data[params.sysLabelIds]
        let map = {}
        let statusValueMap = {}
        if(that.data.userInfo && that.data.userInfo.userType == 2){
          orderStatusName = res.result.data['17']
          statusValueMap = {
            1: [],
            2: [],
            3: [],
            4: [],
            5: [],
          }
          list.forEach(item => {
            let obj = {
              id: item.id,
              sysValueName: item.sysValueName,
            }
            statusList.push(obj)
            map[item.id] = item.sysValueName
            if(item.id == 79){
              statusValueMap[1].push(
                {
                  label: item.sysValueName,
                  value: item.id
                }
              )
            }
            // else if(item.id == 80){
            //   statusValueMap[1].push(
            //     {
            //       label: item.sysValueName,
            //       value: item.id
            //     }
            //   )
            // }
            else if(item.id == 81){
              statusValueMap[1].push(
                {
                  label: item.sysValueName,
                  value: item.id
                }
              )
            }else if(item.id == 82){
              statusValueMap[2].push(
                {
                  label: item.sysValueName,
                  value: item.id
                }
              )
            }else if(item.id == 83){
              statusValueMap[1].push(
                {
                  label: item.sysValueName,
                  value: item.id
                }
              )
            }else if(item.id == 84){
              statusValueMap[1].push(
                {
                  label: item.sysValueName,
                  value: item.id
                }
              )
            }else if(item.id == 85){
              statusValueMap[1].push(
                {
                  label: item.sysValueName,
                  value: item.id
                }
              )
            }else if(item.id == 86){
              statusValueMap[3].push(
                {
                  label: item.sysValueName,
                  value: item.id
                }
              )
            }else if(item.id == 87){
              statusValueMap[3].push(
                {
                  label: item.sysValueName,
                  value: item.id
                }
              )
            }else if(item.id == 88){
              statusValueMap[4].push(
                {
                  label: item.sysValueName,
                  value: item.id
                }
              )
            }else if(item.id == 90){
              statusValueMap[4].push(
                {
                  label: item.sysValueName,
                  value: item.id
                }
              )
            }else if(item.id == 95){
              statusValueMap[1].push(
                  {
                    label: item.sysValueName,
                    value: item.id
                  }
              )
            }else if(item.id == 99){
              statusValueMap[4].push(
                {
                  label: item.sysValueName,
                  value: item.id
                }
              )
            }

          })
        }else if(that.data.userInfo && that.data.userInfo.userType == 1){
          orderStatusName = res.result.data['16']
          // 渠道
          statusValueMap = {
            1: [],
            2: [],
            3: [],
            4: [],
            5: [],
          }
          list.forEach(item => {
            let obj = {
              id: item.id,
              sysValueName: item.sysValueName,
            }
            statusList.push(obj)
            map[item.id] = item.sysValueName
            if(item.id == 71){
              statusValueMap[1].push(
                {
                  label: item.sysValueName,
                  value: item.id
                }
              )
            }else if(item.id == 72){
              statusValueMap[2].push(
                {
                  label: item.sysValueName,
                  value: item.id
                }
              )
            }else if(item.id == 73){
              statusValueMap[1].push(
                {
                  label: item.sysValueName,
                  value: item.id
                }
              )
            }else if(item.id == 74){
              statusValueMap[3].push(
                {
                  label: item.sysValueName,
                  value: item.id
                }
              )
            }
            else if(item.id == 75){
              statusValueMap[3].push(
                {
                  label: item.sysValueName,
                  value: item.id
                }
              )
            }
            else if(item.id == 76){
              statusValueMap[3].push(
                {
                  label: item.sysValueName,
                  value: item.id
                }
              )
            }
            // else if(item.id == 77){
            //   statusValueMap[2].push(
            //     {
            //       label: item.sysValueName,
            //       value: item.id
            //     }
            //   )
            // }
            else if(item.id == 78){
              statusValueMap[4].push(
                {
                  label: item.sysValueName,
                  value: item.id
                }
              )
            }
            // else if(item.id == 91){
            //   statusValueMap[4].push(
            //     {
            //       label: item.sysValueName,
            //       value: item.id
            //     }
            //   )
            // }
            else if(item.id == 92){
              statusValueMap[4].push(
                {
                  label: item.sysValueName,
                  value: item.id
                }
              )
            }else if(item.id == 93){
              statusValueMap[4].push(
                {
                  label: item.sysValueName,
                  value: item.id
                }
              )
            }else if(item.id == 94){
              statusValueMap[4].push(
                {
                  label: item.sysValueName,
                  value: item.id
                }
              )
            }
          })
        }
        let a = []
        // statusValueMap[1].forEach(item => {
        //   a.push(item)
        // })
        // statusValueMap[2].forEach(item => {
        //   a.push(item)
        // })
        // statusValueMap[3].forEach(item => {
        //   a.push(item)
        // })
        // statusValueMap[4].forEach(item => {
        //   a.push(item)
        // })
        statusValueMap[5] = a
        console.log('statusValueMap', statusValueMap)
        console.log('statusMap', map)
        wx.setStorageSync('statusMap', map)
        that.setData({
          statusSearchList: statusList,
          statusMap: map,
          statusValueMap: statusValueMap,
          statusValueList: statusValueMap[1],
          orderStatusName: orderStatusName
        })
        that.getList()
      }
    });
  },

  onLoad: function (options) {

  },
  onShow: function (){
    if(wx.getStorageSync('token')){
      this.setData({
        token: wx.getStorageSync('token')
      })
    }
    if(wx.getStorageSync('userInfo')){
      let userInfo = wx.getStorageSync('userInfo')
      this.setData({
        userInfo: wx.getStorageSync('userInfo'),
        showName: userInfo.telephone,
      })
      wx.setNavigationBarTitle({
        title: (this.data.userInfo && this.data.userInfo.userType == 1) ? ('牧鲸渠道系统' + (this.data.userInfo.touristType && this.data.userInfo.touristType == 2 ? '(游客模式)' : '')) : (this.data.userInfo && this.data.userInfo.userType == 2) ? '牧鲸选品系统' : '牧鲸选品系统',
      })
      this.setData({
        statusValueList: this.data.statusValueMap[1]
      })
      let a = wx.getStorageSync('getList')
      if(a){
        this.getSysList()
        this.resetPage()
        this.getSearchStatusList()
        wx.removeStorageSync('getList')
      }
    }
    const userinfo = wx.getStorageSync('userInfo');
    if(userinfo.userType === 5){
      wx.redirectTo({
        url: '/pages/chooseMedium/chooseMedium',
      })
    }
  },
  onShow1: function () {
    let that = this
    init.call(this);
    
    if(wx.getStorageSync('token')){
      this.setData({
        token: wx.getStorageSync('token')
      })
    }
    if(wx.getStorageSync('userInfo')){
      let userInfo = wx.getStorageSync('userInfo')
      this.setData({
        userInfo: wx.getStorageSync('userInfo'),
        showName: userInfo.telephone,
      })
      wx.setNavigationBarTitle({
        title: (this.data.userInfo && this.data.userInfo.userType == 1) ? ('牧鲸渠道系统' + (this.data.userInfo.touristType && this.data.userInfo.touristType == 2 ? '(游客模式)' : '')) : (this.data.userInfo && this.data.userInfo.userType == 2) ? '牧鲸选品系统' : '牧鲸选品系统',
      })
      this.setData({
        statusValueList: this.data.statusValueMap[1]
      })
      this.getSysList()
      this.resetPage()
      this.getSearchStatusList()
    }
  },
  
  /*页面相关事件处理函数--监听用户下拉动作*/
  onPullDownRefresh: function () {
    this.data.current = 1;
    this.data.pageSize = 10;
    this.setData({
      scrollTop: 0
    });
    this.resetPage();
    this.getList();
    wx.stopPullDownRefresh();
  },

  /*页面上拉触底事件的处理函数*/
  onReachBottom: function () {
    if (this.data.current + 1 > this.data.allPage) {
      return;
    } else {
      this.data.current = this.data.current + 1;
      this.setData({
        current: this.data.current
      });
      this.getList();
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return {
      title: '牧鲸选品',
      path: 'pages/index/index',
      imageUrl: '/images/share.jpg'
    }
  },

  onReady(){
    if(wx.getStorageSync('userInfo')){
      let userInfo = wx.getStorageSync('userInfo')
      this.setData({
        userInfo: wx.getStorageSync('userInfo'),
      })
      wx.setNavigationBarTitle({
        title: (this.data.userInfo && this.data.userInfo.userType == 1) ? ('牧鲸渠道系统' + (this.data.userInfo.touristType && this.data.userInfo.touristType == 2 ? '(游客模式)' : '')) : (this.data.userInfo && this.data.userInfo.userType == 2) ? '牧鲸选品系统' : '牧鲸选品系统',
      })
    }
    this.onShow1()
  },
  
  // 获取数据列表
  resetPage() {
    this.data.current = 1;
    this.data.pageSize = 10;
    this.data.allPage = 0;
    this.setData({
      current: this.data.current,
      allPage: this.data.allPage,
      list: [],
      tableData: [],
      navChangeIndex: 0,
    });
  },
  getStatusName(item){
    let userInfo = this.data.userInfo
    let userId = userInfo.userId
    let statusMap = this.data.statusMap
    let statusName = ''
    if(userInfo.userType == 1){
      // 渠道商的订单状态
      if(item.status == 2){
        // 未提交核价
        statusName = statusMap[71]
        // 已提交核价并且用户id是自己的，才判断为已提交
        let a = ',' + item.submitCheckUserIds + ','
        let b = ',' + userId + ','
        if(item.isSubmitCheck && item.isSubmitCheck == 2 && a.indexOf(b) > -1){
          statusName = statusMap[72]
        }
        // 判断是否为重新推送的订单
        if(item.isBackPush && item.isBackPush == 2){
          statusName = statusMap[73]
          let a = ',' + item.submitCheckUserIds + ','
          let b = ',' + userId + ','
          if(a.indexOf(b) > -1){
            statusName = statusMap[72]
          }else{
            statusName = statusMap[71]
          }
        }
      } else if(item.status == 3){

        statusName = statusMap[72]
         // 已提交核价并且用户id是自己的，才判断为已提交
         let a = ',' + item.submitCheckUserIds + ','
         let b = ',' + userId + ','
         if(item.isSubmitCheck && item.isSubmitCheck == 2 && a.indexOf(b) > -1){
           statusName = statusMap[72]
         }
      } else if(item.status == 4){
        // 没有设定截止时间，展示等消息
        if(!item.biddingOneEndTime){
          statusName = statusMap[72]
        }else{
          // 开拓者没有分配渠道或者没有分配该渠道，展示等消息
          if(!item.biddingPushChannelUserIds){
            statusName = statusMap[72]
          }else{
            let a = ',' + item.biddingPushChannelUserIds + ','
            let b = ',' + userId + ','
            if(a.indexOf(b) > -1){
              let c = ',' + item.biddingFirstUserIds + ','
              if(c.indexOf(b) > -1){
                statusName = statusMap[75]
              }else{
                statusName = statusMap[74]
              }
            }else{
              statusName = statusMap[72]
            }
          }
        }
      } else if(item.status == 5){
        statusName = statusMap[75]
        if(item.biddingStartTwo && item.biddingStartTwo == 2){
          let a = ',' + item.biddingSecondUserIds + ','
          let b = ',' + userId + ','
          if(a.indexOf(b) > -1){
            statusName = statusMap[77]
          }else{
            statusName = statusMap[76]
          }
        }
      } else if(item.status == 7){
        statusName = statusMap[78]
        if(item.lastUserId && item.lastUserId == this.data.userInfo.userId){
          statusName = statusMap[93]
        }
        if(item.lastUserId && item.lastUserId != this.data.userInfo.userId){
          statusName = statusMap[92]
        }
      } else if(item.status == 8){
        statusName = statusMap[90]
      }
      if(item.isNextPush == 2 && item.pushUserIds && ((',' + item.pushUserIds + ',').indexOf(',' + this.data.userInfo.userId + ',') > -1)){
        // statusName += '，您没有权利参与竞价'
      }
      if ((item.status == 2 || item.status == 4 || item.status == 5) && item.channelRefuseIds && (',' + item.channelRefuseIds + ',').indexOf(',' + this.data.userInfo.userId + ',') > -1){
        statusName = statusMap[94]
      }
    }else if(userInfo.userType == 2){
      // 开拓者的订单状态
      if(item.status == 1){
        statusName = statusMap[79]
      } else if(item.status == 2){
        // 未收到核价的时候
        statusName = statusMap[80]
        // 判断是否为发布者重新推送的订单
        if(item.isBackPush && item.isBackPush == 2){
          statusName = statusMap[83]
        }
        //  已收到任一渠道商提交的核价
        if(item.isSubmitCheck && item.isSubmitCheck == 2){
          statusName = statusMap[81]
        }
      } else if(item.status == 3){
        statusName = statusMap[82]
        // if(item.isSubmitCheck && item.isSubmitCheck == 2){
        //   statusName = statusMap[81]
        // }
      } else if(item.status == 4){
        if(!item.biddingOneEndTime){
          statusName = statusMap[85]
        }else{
          statusName = statusMap[86]
        }
      } else if(item.status == 5){
        statusName = statusMap[87]
      } else if(item.status == 8){
        statusName = statusMap[90]
      } else {
        statusName = statusMap[88]
      }
      if(item.isNextPush == 2 && item.pushUserIds && ((',' + item.pushUserIds + ',').indexOf(',' + this.data.userInfo.userId + ',') > -1)){
        statusName = '已转移，' + statusName
      }
      if(item.pushChannelUserIds && item.pushChannelUserIds.trim() && item.isSubmitCheck != 2){
        statusName = statusName + '，新订单' 
      }
      if(item.projectStatus == 9){
        statusName = statusMap[88]
      }
    }else{
      // 其他
      statusName = '未知'
    }
    return statusName;
  },
  getList() {
    this.getHomeShowNum()
    let params = {
      pageNum: this.data.current,
      pageSize: this.data.pageSize
    }
    if(this.data.keyword){
      params.keyword = this.data.keyword
    }
    if(this.data.indexArea){
      params.area = this.data.areaSearchList[this.data.indexArea].id
    }
    if(this.data.indexStatus || this.data.indexStatus == 0){
      params.status = this.data.statusSearchList[this.data.indexStatus].id
    }
    if(this.data.indexBussiness && this.data.indexBussiness != 0){
      params.bussinessUsername = this.data.bussinessSearchList[this.data.indexBussiness].sysValueName
    }
    if(this.data.indexPermissionUsername && this.data.indexPermissionUsername != 0){
      params.permissionUsername = this.data.permissionUsernameSearchList[this.data.indexPermissionUsername].sysValueName
    }
    if(this.data.indexCateUsername){
      params.cateName = this.data.cateUsernameSearchList[this.data.indexCateUsername].id
    }
    if(this.data.searchStartDate){
      params.startTime = new Date(this.data.searchStartDate).getTime()
    }
    if(this.data.searchEndDate){
      params.endTime = new Date(this.data.searchEndDate).getTime()
    }
    if(this.data.startTime){
      params.startTime = new Date(this.data.startTime).getTime()
    }
    if(this.data.endTime){
      params.endTime = new Date(this.data.endTime).getTime()
    }
    if(this.data.statusValueList && this.data.statusValueList.length > 0){
      let statusList = []
      var isAllNoChoose = true
      this.data.statusValueList.forEach(item => {
        if(item.isChoose){
          isAllNoChoose = false
          statusList.push(item.value)
        }
      })
      if(isAllNoChoose){
        this.data.statusValueList.forEach(item => {
          statusList.push(item.value)
        })
      }
      params.statusList = statusList.join(",")
    }
    wx.showLoading({
      title: '加载中',
      mask: true,
    })
    server.post("/app/user/orderList", params).then(res => {
      if (res.key === 1000) {
        let tableData = []
        res.result.list.forEach(item => {
          item.createDate = formatDateCN(new Date(item.createTime))
          if(this.data.userInfo && this.data.userInfo.userType != 1){
            //判断是开拓者，并且不是助理的情况
            if(item.pushSureCheckDate){
              item.showDate = this.getHourMinString2(item.pushSureCheckDate)
            }else{
              if(item.pushSureCheckType == 1 && item.pushTime){
                item.showDate = this.getHourMinString(new Date().getTime() - new Date(item.pushTime).getTime())
              }else if(item.pushSureCheckType == 2 && item.pushSureCheckTime){
                item.showDate = this.getHourMinString(new Date(item.pushSureCheckTime).getTime() - new Date(item.pushTime).getTime())
              }
            }
          }
          if(item.cateNames){
            let cateNameList = item.cateNames.split(";")
            item.cateNameList = cateNameList.splice(0, cateNameList.length - 1)
          }
          if (item.childOrderList) {
            this.handleChildOrderList(item.childOrderList)
          }
          // if(item.areaName){
          //   item.areaName = item.areaName.substring(0,1)
          // }
          // item.statusName = this.getStatusName(item)
          item.statusName = this.getStatusName2(item)
          item["isShowChild"] = false
          tableData.push(item)
        })
        let columns = [
          { title: '操作', key: 'statusCol', width: '350rpx' },
          { title: '状态', key: 'statusName', width: '350rpx' },
          { title: '项目名称', key: 'projectName', width: '400rpx' },
          { title: '时间', key: 'createDate', width: '350rpx' },
          { title: '品类', key: 'cateNames', width: '350rpx' },
          { title: '品牌', key: 'brands', width: '350rpx' },
          { title: '总数', key: 'totalNum', width: '350rpx' },
          { title: '总货值', key: 'totalPrice', width: '350rpx' },
        ]
        let list1 = []
        if(params.pageNum == 1){
          list1 = tableData
        }else{
          list1 = this.data.tableData.concat(tableData)
        }
        this.setData({
          columns: columns,
          tableData: list1,
          allPage: res.result.allPageNumber
        })
      }
    });
    wx.hideLoading()

  },
  getHourMinString2(v){
    // 计算传入的值的时与分
    let minutes = Math.floor(v / 60);
    let hours = Math.floor(minutes / 60);
    let min = minutes % 60;
    let h = hours > 0 ? ((hours > 10 ? hours : ("0" + hours)) + ":") : "00:"
    min = min >= 10 ? min : ("0" + min)
    let finalTime = h + min
    return finalTime
  },
  getHourMinString(t){
    let v = Math.floor(t / 1000)
    // 计算传入的值的时与分
    let minutes = Math.floor(v / 60);
    let hours = Math.floor(minutes / 60);
    let min = minutes % 60;
    let h = hours > 0 ? ((hours > 10 ? hours : ("0" + hours)) + ":") : "00:"
    min = min >= 10 ? min : ("0" + min)
    let finalTime = h + min
    return finalTime
  },
  handleChildOrderList(list){
    list.forEach(child => {
      child.createDate = formatDateCN(new Date(child.createTime))
      child.statusName = this.getStatusName2(child)
      if(child.cateNames){
        let cateNameList = child.cateNames.split(";")
        child.cateNameList = cateNameList.splice(0, cateNameList.length - 1)
      }
      if (child.childOrderList) {
        this.handleChildOrderList(child.childOrderList)
      }
    })
  },
  getStatusName2(item) {
    const isAbandon = item.isAbandon
    const status = item.orderStatus
    const orderIsNextPush = item.orderIsNextPush
    return (orderIsNextPush == 2 ? '已转移，' : (isAbandon == 2 ? '已放弃，' : '')) + this.data.orderStatusName.find(label => label.id == status).sysValueName
  },
  // 点击下拉显示框
  selectTapArea() {
    this.setData({
      showArea: !this.data.showArea
    });
  },
  // 点击下拉列表
  optionTapArea(e) {
    let index = e.detail.value;//获取点击的下拉列表的下标
    if (index && index > 0){
      let areaId = this.data.areaSearchList[index].id
      let showBusinessList = []
      this.data.bussinessSearchAllList.forEach(item => {
        if(item && item.pid && item.pid == areaId){
          showBusinessList.push(item)
        }
      })
      showBusinessList.unshift({
        sysValueName: '全部'
      })
      this.setData({
        bussinessSearchList: showBusinessList,
      })
    }
    this.setData({
      indexArea: index,
      current: 1,
      indexBussiness: null,
    });
    setTimeout(()=>{
      this.getList()
    }, 500)
  },
  selectTapStatus() {
    this.setData({
      showStatus: !this.data.showStatus
    });
  },
  optionTapStatus(e) {
    let that = this
    let Index = e.detail.value;//获取点击的下拉列表的下标
    this.setData({
      indexStatus: Index,
      current: 1,
      // showStatus: !this.data.showStatus
    });
    setTimeout(()=>{
      this.getList()
    }, 500)
  },
  // 点击下拉显示框
  selectTapBussiness() {
    this.setData({
      showBussiness: !this.data.showBussiness
    });
  },
  // 点击下拉列表
  optionTapBussiness(e) {
    let that = this
    let Index = e.detail.value;//获取点击的下拉列表的下标
    this.setData({
      indexBussiness: Index,
      current: 1,
      // showBussiness: !this.data.showBussiness
    });
    setTimeout(()=>{
      this.getList()
    }, 500)
  },
  // 点击下拉显示框
  selectTapPermissionUsername() {
    this.setData({
      showPermissionUsername: !this.data.showPermissionUsername
    });
  },
  // 点击下拉列表
  optionTapPermissionUsername(e) {
    let that = this
    let Index = e.detail.value;//获取点击的下拉列表的下标
    this.setData({
      indexPermissionUsername: Index,
      current: 1,
      // showPermissionUsername: !this.data.showPermissionUsername
    });
    setTimeout(()=>{
      this.getList()
    }, 500)
  },
  // 点击下拉显示框
  selectTapCateUsername() {
    this.setData({
      showCateUsername: !this.data.showCateUsername
    });
  },
  // 点击下拉列表
  optionTapCateUsername(e) {
    let Index = e.detail.value;//获取点击的下拉列表的下标
    this.setData({
      indexCateUsername: Index,
      current: 1,
      // showCateUsername: !this.data.showCateUsername
    });
    setTimeout(()=>{
      this.getList()
    }, 500)
  },
  getSysList() {
    let params = {
      sysLabelIds: "2,3"
    }
    if(this.data.userInfo.userType == 2){
      params.sysLabelIds = "2,3,7,8"
    }
    wx.showLoading({
      title: '加载中',
      mask: true,
    })
    server.post("/app/user/getSysLabelValueManageList", params).then(res => {
      if (res.key === 1000) {
        let data = res.result.data
        let cateUsernameSearchList = data[2]
        let areaSearchList = data[3]
        let bussinessSearchList = []
        if(this.data.userInfo.userType == 2){
          bussinessSearchList = data[7]
        }
        let permissionUsernameSearchList = []
        if(this.data.userInfo.userType == 2){
          permissionUsernameSearchList = data[8]
        }
        cateUsernameSearchList.unshift({
          sysValueName: '全部'
        })
        areaSearchList.unshift({
          sysValueName: '全部'
        })
        bussinessSearchList.unshift({
          sysValueName: '全部'
        })
        permissionUsernameSearchList.unshift({
          sysValueName: '全部'
        })
        this.setData({
          areaSearchList: areaSearchList,
          bussinessSearchList: bussinessSearchList,
          bussinessSearchAllList: bussinessSearchList,
          cateUsernameSearchList: cateUsernameSearchList,
          permissionUsernameSearchList: permissionUsernameSearchList,
        })
      }
    });
    wx.hideLoading()
  },
  getHomeShowNum() {
    if(this.data.userInfo.userType != 1 && this.data.userInfo.userType != 2){
      return
    }
    let params = {}
    wx.showLoading({
      title: '加载中',
      mask: true,
    })
    server.post("/app/user/getHomeShowNum", params).then(res => {
      if (res.key === 1000) {
        let data = res.result.data
        let status1Num = 0
        let status2Num = 0
        if(this.data.userInfo.userType == 1){
          status1Num = status1Num + data[71] + data[73]
          status2Num = status2Num + data[74] + data[75] + data[76]
        }else if(this.data.userInfo.userType == 2){
          status1Num = status1Num + data[79] + data[81] + data[83] + data[85] + data[95]
          status2Num = status2Num + data[86] + data[87]
        }
        this.setData({
          status1Num: status1Num,
          status2Num: status2Num,
          statusNumMap: data
        })
      }
    });
    wx.hideLoading()
  },
})